const rule = require("../rule");
const CardBox = require("../CardBox");
const Card = require("../Card");
const Player = require("../Player");
const CARDBOX = new CardBox();
const tester = new Player("test1");

var card_list = "梅花_1,方块_2,梅花_3,方块_4,梅花_5,黑桃_6,黑桃_7,红心_8,方块_9,黑桃_10,方块_J,黑桃_Q,黑桃_K"
	.split(",")
	.map(txt => Card.getIns(txt));
var res_info = {};
console.log(rule.is_one_long(card_list, res_info));
console.log(JSON.stringify(res_info));

var card_list = "梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_6,梅花_7,梅花_8,梅花_9,梅花_10,梅花_J,梅花_Q,梅花_K"
	.split(",")
	.map(txt => Card.getIns(txt));
var res_info = {};
console.log(rule.is_king_long(card_list, res_info));
console.log(JSON.stringify(res_info));

var card_list = "梅花_1,梅花_2,方块_1,方块_2,梅花_5,梅花_6,黑桃_5,红心_6,梅花_9,梅花_10,黑桃_9,黑桃_10,梅花_K"
	.split(",")
	.map(txt => Card.getIns(txt));
console.log(rule.is_six_pair(card_list));
var card_list = "梅花_1,梅花_2,方块_1,方块_2,梅花_5,梅花_6,黑桃_5,红心_6,梅花_9,梅花_10,黑桃_9,黑桃_10,黑桃_1"
	.split(",")
	.map(txt => Card.getIns(txt));
console.log(rule.is_six_pair(card_list));

[
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_6,梅花_7,梅花_8,梅花_9,梅花_10,梅花_J,梅花_Q,梅花_K",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_1,梅花_2,梅花_3",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_6,梅花_7,梅花_8,梅花_9,梅花_10,梅花_4,梅花_5,梅花_6",
	"梅花_2,梅花_3,梅花_4,梅花_5,梅花_6,梅花_6,梅花_7,梅花_5,梅花_9,梅花_10,梅花_8,梅花_7,梅花_J",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_10,梅花_J,梅花_Q,梅花_K,梅花_1,梅花_2,梅花_3,梅花_1",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_9,梅花_10,梅花_J,梅花_1,梅花_10,梅花_J,梅花_Q,梅花_K",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_7,梅花_8,梅花_9,梅花_10,梅花_J,梅花_Q,梅花_K,梅花_1",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_5,梅花_6,梅花_7,梅花_8,梅花_9,梅花_4,梅花_5,梅花_6"
].forEach(function(card_name_list, i) {
	var card_list = card_name_list.split(",").map(txt => Card.getIns(txt));
	var res = rule.check_three_straight(card_list);
	console.log(
		`手牌${i}：`,
		JSON.stringify(card_list).replace(/\"/g, "").replace(/梅花_/g, "")
	);
	console.log(
		"三顺子：",
		JSON.stringify(res)
			.replace(/\"/g, "")
			.replace("top", "头部")
			.replace("mid", "中部")
			.replace("btm", "尾部")
			.replace(/梅花_/g, ""),
		"\n"
	);
});
[
	"梅花_1,梅花_3,梅花_5,黑桃_6,黑桃_7,黑桃_10,黑桃_Q,黑桃_1,方块_10,方块_J,方块_Q,方块_K,方块_J",
	"黑桃_1,黑桃_3,黑桃_5,黑桃_6,黑桃_7,黑桃_10,黑桃_Q,黑桃_1,方块_10,方块_J,方块_Q,方块_K,方块_J",
	"黑桃_1,黑桃_3,黑桃_5,黑桃_6,黑桃_7,黑桃_10,黑桃_Q,黑桃_1,黑桃_10,黑桃_J,方块_Q,方块_K,方块_J",
	"红心_3,红心_6,红心_Q,梅花_2,梅花_4,梅花_7,梅花_8,梅花_Q,黑桃_1,黑桃_3,黑桃_6,黑桃_7,黑桃_10"
].forEach(function(card_name_list, i) {
	var card_list = card_name_list.split(",").map(txt => Card.getIns(txt));
	var res_info = {};
	console.assert(rule.is_three_flush(card_list, res_info), "三同花");
	console.log(JSON.stringify(res_info));
});
[
	"黑桃_3,梅花_3,梅花_5,红心_5,黑桃_7,红心_7,红心_1,黑桃_1,红心_J,方块_J,方块_Q,黑桃_Q,方块_J",
	"梅花_1,梅花_2,梅花_3,梅花_4,梅花_5,梅花_6,梅花_7,方块_1,方块_2,方块_3,方块_4,方块_5,方块_6"
].forEach(function(card_name_list, i) {
	var card_list = card_name_list.split(",").map(txt => Card.getIns(txt));
	var res_info = {};
	try {
		console.assert(rule.is_six_pair(card_list, res_info), "六对半");
		console.log(JSON.stringify(res_info));
	} catch (e) {
		if (i >= 1) {
			console.log("六对半不能有同花顺和炸弹")
		}else{
			throw e;
		}
	}
});
